﻿using Arction.Wpf.BindableCharting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WPF_ExampleSpectrum3D_Demo
{
    /// <summary>
    /// Interaction logic for CameraEditor.xaml
    /// </summary>
    public partial class CameraEditor : UserControl
    {
        public CameraEditor()
        {
            InitializeComponent();
            DistanceRS = 250;
        }

        public static DependencyProperty widthRSProperty =
            DependencyProperty.Register(
            "widthRS",
            typeof(int),
            typeof(CameraEditor),
            new PropertyMetadata(100)
        );

        public int widthRS
        {
            get { return (int)GetValue(widthRSProperty); }
            set { SetValue(widthRSProperty, value); }
        }

        public static DependencyProperty heightRSProperty =
            DependencyProperty.Register(
            "heightRS",
            typeof(int),
            typeof(CameraEditor),
        new PropertyMetadata(50)
        );

        public int heightRS
        {
            get { return (int)GetValue(heightRSProperty); }
            set { SetValue(heightRSProperty, value); }
        }

        public static DependencyProperty depthRSProperty =
            DependencyProperty.Register(
            "depthRS",
            typeof(int),
            typeof(CameraEditor),
        new PropertyMetadata(100)
        );

        public int depthRS
        {
            get { return (int)GetValue(depthRSProperty); }
            set { SetValue(depthRSProperty, value); }
        }

        public static DependencyProperty cameraOrientationRSProperty =
            DependencyProperty.Register(
            "cameraOrientationRS",
            typeof(OrientationModes),
            typeof(CameraEditor),
            new PropertyMetadata(OrientationModes.ZXY_Extrinsic)
        );

        public OrientationModes cameraOrientationRS
        {
            get { return (OrientationModes)GetValue(cameraOrientationRSProperty); }
            set { SetValue(cameraOrientationRSProperty, value); }
        }
        public static DependencyProperty projectionTypeRSProperty =
            DependencyProperty.Register(
            "projectionTypeRS",
            typeof(ProjectionType),
            typeof(CameraEditor),
            new PropertyMetadata(ProjectionType.Perspective)
        );

        public ProjectionType projectionTypeRS
        {
            get { return (ProjectionType)GetValue(projectionTypeRSProperty); }
            set { SetValue(projectionTypeRSProperty, value); }
        }

        public static DependencyProperty VerticalRotationRSProperty =
       DependencyProperty.Register(
       "VerticalRotationRS",
       typeof(double),
       typeof(CameraEditor),
       new PropertyMetadata(18.6)
        );

        public double VerticalRotationRS
        {
            get { return (double)GetValue(VerticalRotationRSProperty); }
            set { SetValue(VerticalRotationRSProperty, value); }
        }
        public static DependencyProperty HorizontalRotationRSProperty =
       DependencyProperty.Register(
       "HorizontalRotationRS",
       typeof(double),
       typeof(CameraEditor),
       new PropertyMetadata(-23.6)
        );

        public double HorizontalRotationRS
        {
            get { return (double)GetValue(HorizontalRotationRSProperty); }
            set { SetValue(HorizontalRotationRSProperty, value); }
        }
        public static DependencyProperty SideRotationRSProperty =
       DependencyProperty.Register(
       "SideRotationRS",
       typeof(double),
       typeof(CameraEditor),
       new PropertyMetadata(0.0)
       );

        public double SideRotationRS
        {
            get { return (double)GetValue(SideRotationRSProperty); }
            set { SetValue(SideRotationRSProperty, value); }
        }
        public static DependencyProperty DistanceRSProperty =
        DependencyProperty.Register(
        "DistanceRS",
        typeof(double),
        typeof(CameraEditor),
        new PropertyMetadata(163.0)
        );

        public double DistanceRS
        {
            get { return (double)GetValue(DistanceRSProperty); }
            set { SetValue(DistanceRSProperty, value); }
        }


        private void textBoxExWidth_TextChanged(object sender, TextChangedEventArgs e)
        {
            int outWidth;
            if (int.TryParse(textBoxExWidth.Text, out outWidth))
            {
                widthRS = outWidth;
            }
            e.Handled = true;
        }

        private void textBoxExHeight_TextChanged(object sender, TextChangedEventArgs e)
        {
            int outHeight;
            if (int.TryParse(textBoxExHeight.Text, out outHeight))
            {
                heightRS = outHeight;
            }
            e.Handled = true;
        }

        private void textBoxExDepth_TextChanged(object sender, TextChangedEventArgs e)
        {
            int outDepth;
            if (int.TryParse(textBoxExDepth.Text, out outDepth))
            {
                depthRS = outDepth;
            }
            e.Handled = true;
        }

        private void comboBoxCamera_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (comboBoxCamera.SelectedIndex == 0)
            {
                cameraOrientationRS = OrientationModes.XYZ_Mixed;
            }
            else if (comboBoxCamera.SelectedIndex == 1)
            {
                cameraOrientationRS = OrientationModes.ZXY_Extrinsic;
            }
            e.Handled = true;
        }

        private void comboBoxProjection_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (comboBoxProjection.SelectedIndex == 0)
            {
                projectionTypeRS = ProjectionType.Orthographic;
            }
            else if (comboBoxProjection.SelectedIndex == 1)
            {
                projectionTypeRS = ProjectionType.OrthographicLegacy;
            }
            else if (comboBoxProjection.SelectedIndex == 2)
            {
                projectionTypeRS = ProjectionType.Perspective;
            }
            e.Handled = true;
        }

        private void tbVerticalRotation_TextChanged(object sender, TextChangedEventArgs e)
        {
            double newVert;
            if (double.TryParse(tbVerticalRotation.Text, out newVert))
            {
                VerticalRotationRS = Math.Round(newVert, 0);
            }
            e.Handled = true;
        }

        private void tbHorizontalRotation_TextChanged(object sender, TextChangedEventArgs e)
        {
            double newHori;
            if (double.TryParse(tbHorizontalRotation.Text, out newHori))
            {
                HorizontalRotationRS = Math.Round(newHori, 0);
            }
            e.Handled = true;
        }

        private void tbSideRotation_TextChanged(object sender, TextChangedEventArgs e)
        {
            double newSide;
            if (double.TryParse(tbSideRotation.Text, out newSide))
            {
                SideRotationRS = Math.Round(newSide, 0);
            }
            e.Handled = true;
        }

        private void tbDistance_TextChanged(object sender, TextChangedEventArgs e)
        {
            double newDist;
            if (double.TryParse(tbDistance.Text, out newDist))
            {
                DistanceRS = Math.Round(newDist, 0);
            }
            e.Handled = true;
        }

        private void sliderVerticalRotation_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            if (e.NewValue != e.OldValue)
            {
                VerticalRotationRS = Math.Round(e.NewValue, 0);
            }
            e.Handled = true;
        }

        private void sliderHorizontalRotation_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            if (e.NewValue != e.OldValue)
            {
                HorizontalRotationRS = Math.Round(e.NewValue, 0);
            }
            e.Handled = true;
        }

        private void sliderSideRotation_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            if (e.NewValue != e.OldValue)
            {
                SideRotationRS = Math.Round(e.NewValue, 0);
            }
            e.Handled = true;
        }

        private void sliderDistance_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            if (e.NewValue != e.OldValue)
            {
                DistanceRS = Math.Round(e.NewValue, 0);
            }
            e.Handled = true;
        }

        private void buttonTopView2D_Click(object sender, RoutedEventArgs e)
        {
            VerticalRotationRS = 90;
            HorizontalRotationRS = 0;
            SideRotationRS = 0;
        }
    }
}
